package com.oa.android.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.oa.android.R;
import com.oa.android.activity.BuzActivity;
import com.oa.android.activity.GuocActivity;
import com.oa.android.entry.GGao;
import com.oa.android.entry.Work;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 公告 on 2016/6/15.
 */
public class WorkAdapter extends BaseAdapter {

    private Context context;
    private List<Work> wrokList;
    private int temp;

    public WorkAdapter(Context context, List<Work> list,int b) {
        this.context = context;
        this.wrokList = list;
        this.temp=b;
    }

    @Override
    public int getCount() {
        return wrokList.size();
    }


    @Override
    public Object getItem(int position) {
        return wrokList.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.work_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        final Work work= wrokList.get(position);
        viewHolder.Title.setText(work.getWORKNAME()+"");
        viewHolder.Content.setText("状态："+work.getWKZTNM());
        viewHolder.time.setText("");
//        if(work.getWKZT().equals("1")){
//            viewHolder.person.setText("");
//        }else if(work.getWKZT().equals("1")){
//
//        }
//        if (temp==1){
//            viewHolder.person.setText(""+work.getEMPNAME());
//        }else{
            viewHolder.person.setText("创建时间："+work.getOPTIME());
//        }
        viewHolder.buz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, BuzActivity.class);
                intent.putExtra("wkfid",wrokList.get(position).getWKFID());
                intent.putExtra("name",wrokList.get(position).getWORKNAME());
                intent.putExtra("SPID",wrokList.get(position).getSPID());
                context.startActivity(intent);
            }
        });
        viewHolder.guoc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, GuocActivity.class);
                intent.putExtra("id",wrokList.get(position).getID());
                intent.putExtra("name",wrokList.get(position).getWORKNAME());
                context.startActivity(intent);
            }
        });

        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.Title)
        TextView Title;
        @InjectView(R.id.time)
        TextView time;
        @InjectView(R.id.Content)
        TextView Content;
        @InjectView(R.id.person)
        TextView person;
        @InjectView(R.id.guoc)
        TextView guoc;
        @InjectView(R.id.buz)
        TextView buz;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
